#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn], b[maxn], n, ans;
namespace A{
	void dfs(int dep) {
		if (dep > n) {
			int sum = 0;
			for (int i = 1; i <= n; i++) 
				for(int j = i - 1; j >= 1; j--)
					if (b[i] == b[j]) {
						if (a[i] == a[j]) sum += a[i];
						break;
					}
			ans = max(ans, sum);
			return ;
		}
		b[dep] = 0;
		dfs(dep + 1);
		b[dep] = 1;
		dfs(dep + 1);
		b[dep] = 0;
	}
	void solve() {
		ans = 0;
		dfs(1);
		cout << ans << endl;
	}
}
namespace B{
	void solve() {
		for (int i = 1; i <= n; i++)
			if (a[i] != a[i - 1])
				b[i] = ~b[i - 1];
			else b[i] = b[i - 1];
		int red = 0, blue = 0, ans = 0;
		for (int i = 1; i <= n; i++) {
			if (b[i] == 0) {
				if (a[i] == a[red]) ans += a[i]; 
				red = i;
			}
			else {
				if (a[i] == a[blue]) ans += a[i];
				blue = i;
			}
		}
		cout << ans << endl;
	}
}
int main(){
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	ios :: sync_with_stdio(false);
	int T;
	cin >> T;
	while (T--) {
		cin >> n;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			b[i] = 0;
		}
		if (n <= 15) {
			A::solve();
		}
		else {
			B::solve();
		}
	}
	return 0;
}
